home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Brailler 0.5ß / Brailler 0.5ß.source / Shell ƒ / other MSG window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  9.6 KB  |  166 lines  |  [TEXT/MMCC]

  1. #include "other MSG window.h"
  2. #include "environment.h"
  3. #include "menus.h"
  4. #include "util.h"
  5. #include "file utilities.h"
  6. #include "main.h"
  7. #include "text twiddling.h"
  8. #include "graphics.h"
  9. #include "window layer.h"
  10. #include "program globals.h"
  11. #include <Folders.h>
  12.  
  13. enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
  14. enum { key_PageUp=0x0b, key_PageDown };
  15. enum { key_Home=0x01 };
  16. enum { key_End=0x04 };
  17.  
  18. #define kGrowBoxSize        15
  19. #define PROGRAMS_LIST_NAME    "\pMSG programs list"
  20. #define kListResourceID        151
  21. #define LIST_CREATOR        'ttxt'
  22. #define LIST_TYPE            'ttro'
  23.  
  24. static    Boolean GetListFromDisk(void);
  25. static    Boolean SetupNewListFile(short fileID);
  26. static    Boolean GetListFromResource(void);
  27. static    unsigned long GetModificationDate(FSSpec *theFS);
  28. static    void PutProductListIntoTE(WindowPtr theWindow);
  29.  
  30. static    short            gOldForegroundTime;        /* stored foreground wait time */
  31. static    Boolean            gIsActive=FALSE;
  32. static    Handle            gTheList=0L;
  33. static    Boolean            gSetupDone=FALSE;
  34.  
  35. void SetupTheOtherMSGWindow(WindowPtr theWindow)
  36. {
  37.     unsigned char    *titleStr="\pOther MSG products";
  38.     Point            topLeft;
  39.     
  40.     SetWindowHeight(theWindow,
  41.         qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
  42.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  43.     SetWindowType(theWindow, zoomDocProc);
  44.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
  45.     topLeft.h=qd.screenBits.bounds.left+10;
  46.     SetWindowTopLeft(theWindow, topLeft);
  47.     SetWindowHasCloseBox(theWindow, TRUE);
  48.     SetWindowMaxDepth(theWindow, 1);
  49.     SetWindowDepth(theWindow, 1);
  50.     SetWindowAutoCenter(theWindow, FALSE);
  51.     SetWindowTitle(theWindow, titleStr);
  52.     SetWindowIsFloat(theWindow, FALSE);
  53.     
  54.     if (gSetupDone)
  55.         return;
  56.     
  57.     if (!GetListFromDisk())
  58.         GetListFromResource();
  59. }
  60.  
  61. void OpenTheOtherMSGWindow(WindowPtr theWindow)
  62. {
  63.     TEHandle        hTE;
  64.     FontInfo        theFontInfo;
  65.     Rect            vScrollBarRect, hScrollBarRect;
  66.     Rect            destRect, viewRect;
  67.     
  68.     hTE=GetWindowTE(theWindow);
  69.     if (hTE==0L)
  70.     {
  71.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  72.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  73.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  74.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  75.         SetWindowVScrollBar(theWindow,
  76.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  77.         SetWindowHScrollBar(theWindow,
  78.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  79.         
  80.         GetTERect(theWindow, &destRect, TRUE);
  81.         viewRect=destRect;
  82.         hTE=TENew(&destRect, &viewRect);
  83.         SetWindowTE(theWindow, hTE);
  84.         TextFont((**hTE).txFont=36);
  85.         TextSize((**hTE).txSize=12);
  86.         TextFace((**hTE).txFace=0);
  87.         GetFontInfo(&theFontInfo);
  88.         (**hTE).fontAscent=theFontInfo.ascent;
  89.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  90.         AdjustViewRect(hTE);
  91.         TEAutoView(TRUE, hTE);
  92.         TESetClickLoop((ProcPtr)MyClikLoop, hTE);
  93.         PutProductListIntoTE(theWindow);
  94.     }
  95.     
  96.     gIsActive=TRUE;
  97.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  98.     AdjustMenus();
  99. }
  100.  
  101. void KeyPressedInOtherMSGWindow(WindowPtr theWindow, unsigned char theChar)
  102. {
  103.     TEHandle        hTE;
  104.     ControlHandle    vScrollBar;
  105.     
  106.     if (gInProgress)
  107.         return;
  108.     
  109.     hTE=GetWindowTE(theWindow);
  110.     vScrollBar=GetWindowVScrollBar(theWindow);
  111.     
  112.     switch (theChar)
  113.     {
  114.         case key_PageUp:
  115.             ScrollActionProc(vScrollBar, inPageUp);
  116.             break;
  117.         case key_PageDown:
  118.             ScrollActionProc(vScrollBar, inPageDown);
  119.             break;
  120.         case key_Home:
  121.             TEPinScroll(0, TEGetHeight((**hTE).nLines, 1, hTE), hTE);
  122.             break;
  123.         case key_End:
  124.             TEPinScroll(0, -TEGetHeight((**hTE).nLines, 1, hTE), hTE);
  125.             break;
  126.         default:
  127.             break;
  128.     }
  129.     
  130.     AdjustVScrollBar(vScrollBar, hTE);
  131. }
  132.  
  133. void MouseClickedInOtherMSGWindow(WindowPtr theWindow, Point thePoint)
  134. {
  135.     short            partCode;
  136.     ControlHandle    theControl;
  137.     short            scrollDistance;
  138.     short            oldSetting;
  139.     ControlActionUPP    scrollActionUPP=NewControlActionProc(ScrollActionProc);
  140.     TEHandle        hTE;
  141.     
  142.     if (gInProgress)
  143.         return;
  144.     
  145.     partCode=FindControl(thePoint, theWindow, &theControl);
  146.     if (theControl==GetWindowVScrollBar(theWindow))
  147.     {
  148.         switch (partCode)
  149.         {
  150.             case inThumb:
  151.                 oldSetting=GetControlValue(theControl);
  152.                 partCode=TrackControl(theControl, thePoint, 0L);
  153.                 if (partCode==inThumb)
  154.                 {
  155.                     scrollDistance=oldSetting-GetControlValue(theControl);
  156.                     if (scrollDistance!=0)
  157.                     {
  158.                         hTE=GetWindowTE(theWindow);
  159.                         TEPinScroll(0, scrollDistance*(**hTE).lineHeight, hTE);
  160.                     }
  161.                 }
  162.                 break;
  163.             case inUpButton:
  164.             case inDownButton:
  165.             case inPageUp:
  166.             case i